package com.example.gerenciadoralunofatec_pg;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class Notas extends Activity {
	// Create the array list of to do items
	public final ArrayList todoItems = new ArrayList();
	// Create the array adapter to bind the array to the listview
	public ArrayAdapter aa;
	public int contador = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_notas);
		// Get references to UI widgets
		ListView myListView = (ListView) findViewById(R.id.listViewNotas);
		aa = new ArrayAdapter(this, android.R.layout.simple_list_item_1,todoItems);
		// Bind the array adapter to the listview.
		myListView.setAdapter(aa);

		atualiza_lista();

		/*
		 * List<Map<String, String>> l = getExampleList(); String[] from =
		 * {"Materia", "Notas"}; int[] to = {android.R.id.text1,
		 * android.R.id.text2};
		 * 
		 * SimpleAdapter ad = new SimpleAdapter(this, l,
		 * android.R.layout.simple_list_item_2, from, to); final ListView lv =
		 * (ListView) findViewById(R.id.listViewNotas); lv.setAdapter(ad);
		 */
	}

	private void atualiza_lista() {
		Intent intent = getIntent();
		String notap1 = intent.getStringExtra("notap1");
		String notap2 = intent.getStringExtra("notap2");
		String notatp = intent.getStringExtra("notatp");
		String materia = intent.getStringExtra("materia");
String imprimir = materia + " P1: " + notap1 + " P2:" + notap2+ " TP:" + notatp;
		if (materia != null) {
			int i = todoItems.size();
			if (i <= 0) {
				i = 0;
				todoItems.add(i, imprimir);
			} else {
				while (i >= 0) {
					todoItems.set(i - 1, todoItems.get(i - 1));
					i = i - 1;
				}
				todoItems.add(todoItems.size(), imprimir);
			}
			aa.notifyDataSetChanged();
		} else {
			todoItems.add(0, "Nenhuma nota");
			aa.notifyDataSetChanged();
		}
	}

	private List<Map<String, String>> getExampleList() {
		Intent intent = getIntent();
		String notap1 = intent.getStringExtra("notap1");
		String notap2 = intent.getStringExtra("notap2");
		String notatp = intent.getStringExtra("notatp");
		String materia = intent.getStringExtra("materia");
		List<Map<String, String>> l = new ArrayList<Map<String, String>>();
		// for(int i=0;i<15;i++){
		// mats[i] = materia;
		// nots[i] = "P1: "+notap1+" P2: "+notap2+" TP: "+notatp;
		Map<String, String> m = new HashMap<String, String>();
		m.put("Materia", materia);
		m.put("Notas", "P1: " + notap1 + " P2: " + notap2 + " TP: " + notatp);
		l.add(m);
		// }
		return l;
	}

	public void novaNota(View view) {
		Intent addNota = new Intent(this, NovaNota.class);
		startActivity(addNota);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.notas, menu);
		return true;
	}

}
